home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / Windows / Interfaces / QD3DRenderer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-03  |  35.9 KB  |  1,060 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        QD3DRenderer.h                                             **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:     Renderer types and routines                                   **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1992-1994 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  *****************************************************************************/
  13. #ifndef QD3DRenderer_h
  14. #define QD3DRenderer_h
  15.  
  16. #if PRAGMA_ONCE
  17.     #pragma once
  18. #endif
  19.  
  20. #include "QD3DView.h"
  21. #include "QD3DSet.h"
  22.  
  23. #if defined(THINK_C) || defined(__SC__)
  24.     #pragma options(!pack_enums, !align_arrays)
  25.     #pragma SC options align=power
  26. #elif defined(__MWERKS__)
  27.     #pragma enumsalwaysint on
  28.     #pragma align_array_members off
  29.     #pragma options align=native
  30. #elif defined(__PPCC__)
  31.     #pragma options align=power
  32. #elif defined(__xlc) || defined(__xlC) || defined(__xlC__) || defined(__XLC121__)
  33.     #pragma options enum=int
  34. #endif
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif    /* __cplusplus */
  39.  
  40. /******************************************************************************
  41.  **                                                                             **
  42.  **                                Renderer Functions                             **
  43.  **                                                                             **
  44.  *****************************************************************************/
  45.  
  46. QD3D_EXPORT TQ3RendererObject Q3Renderer_NewFromType(
  47.     TQ3ObjectType            rendererObjectType);
  48.  
  49. QD3D_EXPORT TQ3ObjectType Q3Renderer_GetType(
  50.     TQ3RendererObject        renderer);
  51.  
  52. /*
  53.     A bit set in this flag to indicates supported features
  54. */
  55. #define kQ3RendererFeatureNone                            (0)            /* Implements nothing */
  56. #define kQ3RendererFeatureFlagHiddenSurfaceRemoval        (1U << 0)    /* Supports hidden surface removal */
  57. #define kQ3RendererFeatureFlagHiddenSurfaceRemovalDeep    (1U << 1)    /* >= 24 bit hidden surface removal precision */
  58. #define kQ3RendererFeatureFlagTexture                    (1U << 2)    /* Textures */
  59. #define kQ3RendererFeatureFlagTextureHighQuality        (1U << 3)    /* High-quality Textures (tri-linear or better) */
  60. #define kQ3RendererFeatureFlagTextureColor                (1U << 4)    /* Full color modulation and highlight of textures */
  61. #define kQ3RendererFeatureFlagTransparency                (1U << 5)    /* Transparency with RGB blending */
  62. #define kQ3RendererFeatureFlagTransparencyAlpha            (1U << 6)    /* Transparency with alpha blending */
  63. #define kQ3RendererFeatureFlagAntialiasing                (1U << 7)    /* AntiAliasing */
  64. #define kQ3RendererFeatureFlagShadows                    (1U << 8)    /* Shadows */
  65.  
  66. typedef unsigned long    TQ3RendererFeatureFlags;
  67.  
  68. /*
  69.     Q3Renderer_GetEditFeatures
  70.         Returns a mask of variable features in the renderer. A 1 bit does not indicate
  71.         that this feature is currently "on", only that it is editable.
  72.         
  73.         You may "set" or "unset" these features using Q3Renderer_SetFeatures.
  74. */
  75. QD3D_EXPORT TQ3Status Q3Renderer_GetEditFeatures(
  76.     TQ3RendererObject            renderer,
  77.     TQ3RendererFeatureFlags        *editableFlags);
  78.  
  79. /*
  80.     Q3Renderer_GetFeatures
  81.         Returns a mask of currently set features in the renderer. A 1 bit indicates
  82.         that this feature is currently "on". Some features may be available but
  83.         not turned on. Some features may be on (always), but not editable.
  84.  
  85.     To get a complete mask of all available features, do:
  86.     
  87.         Q3Renderer_GetEditFeatures(renderer, &editable);
  88.         Q3Renderer_GetFeatures(renderer, &features);
  89.         totalFeatures = editable | features;
  90. */
  91. QD3D_EXPORT TQ3Status Q3Renderer_GetFeatures(
  92.     TQ3RendererObject            renderer,
  93.     TQ3RendererFeatureFlags        *flags);
  94.  
  95. /*
  96.     Q3Renderer_SetFeatures
  97.         Turn on or off editable features in a renderer. 
  98.         Operation is:
  99.             newRendererFlags = 
  100.                 (oldRendererFlags & ~editableFlags) |
  101.                 (flags & editableFlags); 
  102. */
  103. QD3D_EXPORT TQ3Status Q3Renderer_SetFeatures(
  104.     TQ3RendererObject            renderer,
  105.     TQ3RendererFeatureFlags        flags);
  106.  
  107. /*
  108.     Non-blocking, flush all buffered graphics to rasterizer. May or
  109.     may not update the draw context.
  110.  */
  111. QD3D_EXPORT TQ3Status Q3Renderer_Flush(
  112.     TQ3RendererObject        renderer,
  113.     TQ3ViewObject            view);
  114.     
  115. /*
  116.     Blocking, flush all buffered graphics to rasterizer and update
  117.     draw context.
  118.  */
  119. QD3D_EXPORT TQ3Status Q3Renderer_Sync(
  120.     TQ3RendererObject        renderer,
  121.     TQ3ViewObject            view);
  122.  
  123. /*
  124.     Q3Renderer_HasModalConfigure
  125.         Determine if this renderer has a modal settings dialog.
  126.  
  127.     Q3Renderer_ModalConfigure
  128.         Have the renderer pop up a modal dialog box to configure its settings.
  129.  */
  130. QD3D_EXPORT TQ3Boolean Q3Renderer_HasModalConfigure(
  131.     TQ3RendererObject        renderer);
  132.  
  133. QD3D_EXPORT TQ3Status Q3Renderer_ModalConfigure(
  134.     TQ3RendererObject        renderer);
  135.  
  136. #if defined(ESCHER_VER_15) && ESCHER_VER_15
  137. /*
  138.     Q3Renderer_DeleteCaches
  139.     
  140.     Deletes any caches in a renderer created with 
  141.     Q3View_BeginRendererCache and Q3View_EndRendererCache that may be 
  142.     associated with this renderer.
  143.  */
  144. QD3D_EXPORT TQ3Status Q3Renderer_DeleteCaches(
  145.     TQ3RendererObject        renderer);
  146.  
  147. #endif /* ESCHER_VER_15 */
  148.  
  149. /******************************************************************************
  150.  **                                                                             **
  151.  **                        Interactive Renderer Specific Functions                 **
  152.  **                                                                             **
  153.  *****************************************************************************/
  154.  
  155. /* CSG IDs attribute */
  156. #define kQ3AttributeTypeConstructiveSolidGeometryID \
  157.     Q3_OBJECT_TYPE('c','s','g','i')
  158.  
  159. #define kQ3AttributeType_ConstructiveSolidGeometryID \
  160.     kQ3AttributeTypeConstructiveSolidGeometryID
  161.     
  162.  
  163. /* Object IDs, to be applied as attributes on geometries */
  164. #define kQ3SolidGeometryObjA 0
  165. #define kQ3SolidGeometryObjB 1
  166. #define kQ3SolidGeometryObjC 2
  167. #define kQ3SolidGeometryObjD 3
  168. #define kQ3SolidGeometryObjE 4
  169.  
  170. /* Possible CSG equations */
  171.  
  172. typedef enum TQ3CSGEquation {
  173.     kQ3CSGEquationAandB            = (int) 0x88888888,
  174.     kQ3CSGEquationAandnotB         = 0x22222222,
  175.     kQ3CSGEquationAanBonCad        = 0x2F222F22,
  176.     kQ3CSGEquationnotAandB        = 0x44444444,
  177.     kQ3CSGEquationnAaBorCanB    = 0x74747474
  178. } TQ3CSGEquation;
  179.  
  180. typedef enum TQ3HiddenSurfaceRemovalMode {
  181.     kQ3HiddenSurfaceRemovalMode_None,
  182.     kQ3HiddenSurfaceRemovalMode_Shallow,
  183.     kQ3HiddenSurfaceRemovalMode_Deep
  184. } TQ3HiddenSurfaceRemovalMode;
  185.  
  186. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_SetCSGEquation(
  187.     TQ3RendererObject        renderer,
  188.     TQ3CSGEquation            equation);
  189.  
  190. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_GetCSGEquation(
  191.     TQ3RendererObject        renderer,
  192.     TQ3CSGEquation            *equation);
  193.  
  194. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_SetPreferences(
  195.     TQ3RendererObject        renderer,
  196.     long                    vendorID,
  197.     long                    engineID);
  198.  
  199. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_GetPreferences(
  200.     TQ3RendererObject        renderer,
  201.     long                    *vendorID,
  202.     long                    *engineID);
  203.     
  204. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_SetDoubleBufferBypass(
  205.     TQ3RendererObject        renderer,
  206.     TQ3Boolean                bypass);
  207.  
  208. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_GetDoubleBufferBypass(
  209.     TQ3RendererObject        renderer,
  210.     TQ3Boolean                *bypass);
  211.  
  212. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_SetHiddenSurfaceRemovalMode(
  213.     TQ3RendererObject            renderer,
  214.     TQ3HiddenSurfaceRemovalMode    hiddenSurfaceRemovalMode);
  215.  
  216. QD3D_EXPORT TQ3Status Q3InteractiveRenderer_GetHiddenSurfaceRemovalMode(
  217.     TQ3RendererObject            renderer,
  218.     TQ3HiddenSurfaceRemovalMode    *hiddenSurfaceRemovalMode);
  219.  
  220.  
  221. /******************************************************************************
  222.  **                                                                             **
  223.  **                            Plug-in Renderer API                             **
  224.  **                                                                             **
  225.  *****************************************************************************/
  226.  
  227. /*
  228.     These bits should be set in the flag to indicate class supported
  229. */
  230. #define kQ3RendererClassSupportNone                    (0)            /* nothing */
  231. #define kQ3RendererClassSupportFlagDoubleBuffer        (1U << 0)    /* Handle Double buffering */
  232. #define kQ3RendererClassSupportFlagClearBuffer        (1U << 1)    /* Handle DrawContext clearing */
  233.  
  234. typedef unsigned long TQ3RendererClassSupportFlags;
  235.  
  236. /*
  237.     Registration
  238. */
  239. QD3D_EXPORT TQ3ObjectClass Q3RendererClass_Register(
  240.     TQ3ObjectType        objectType,
  241.     char                *rendererName,
  242.     TQ3MetaHandler        metaHandler,
  243.     unsigned long        sizeofClassPrivate,
  244.     unsigned long        sizeofDataPrivate);
  245.  
  246. /******************************************************************************
  247.  **                                                                             **
  248.  **                            Renderer View Tools                                 **
  249.  **                                                                             **
  250.  **                    You may only call these methods from a plug-in             **
  251.  **                                                                             **
  252.  *****************************************************************************/
  253.  
  254. /*
  255.     Call by a renderer to call the user "idle" method, with progress 
  256.     information.
  257.     
  258.     Pass in (view, 0, n) on first call
  259.     Pass in (view, 1..n-1, n) during rendering
  260.     Pass in (view, n, n) upon completion
  261.     
  262.     Note: The user must have supplied an idleProgress method with 
  263.     Q3View_SetIdleProgressMethod. Otherwise, the generic idle method is
  264.     called with no progress data. e.g. the Q3View_SetIdleMethod method
  265.     is called instead. (current and final are ignored, essentially.)
  266.  
  267.     Returns kQ3Failure if rendering is cancelled.
  268.  */
  269. QD3D_EXPORT TQ3Status Q3View_IdleProgress(
  270.      TQ3ViewObject        view,
  271.      unsigned long        current,
  272.      unsigned long        completed);
  273.  
  274. /*
  275.     Called by an asynchronous renderer when it completes a frame.
  276.  */
  277. QD3D_EXPORT TQ3Status Q3View_EndFrame(
  278.      TQ3ViewObject        view);
  279.  
  280. /******************************************************************************
  281.  **                                                                             **
  282.  **                            Renderer AttributeSet Tools                         **
  283.  **                                                                             **
  284.  **                    You may only call these methods from a plug-in             **
  285.  **                                                                             **
  286.  *****************************************************************************/
  287.  
  288. /*
  289.     Faster access to geometry attribute sets.
  290.     
  291.     Returns pointer to INTERNAL data structure for elements and attributes
  292.     in an attributeSet, or NULL if no attribute exists.
  293.     
  294.     For attributes of type kQ3AttributeType..., the internal data structure
  295.     is identical to the data structure used in Q3AttributeSet_Add.
  296. */
  297. QD3D_EXPORT void *Q3AttributeSet_GetPointer(
  298.      TQ3AttributeSet            attributeSet,
  299.      TQ3AttributeType        attributeType);
  300.  
  301. /******************************************************************************
  302.  **                                                                             **
  303.  **                            Renderer Class Methods                             **
  304.  **                                                                             **
  305.  *****************************************************************************/
  306. /*
  307.     Methods from Object
  308.         kQ3MethodTypeObjectClassRegister
  309.         kQ3MethodTypeObjectClassUnregister
  310.         kQ3MethodTypeObjectNew
  311.         kQ3MethodTypeObjectDelete
  312.         kQ3MethodTypeObjectRead
  313.         kQ3MethodTypeObjectTraverse
  314.         kQ3MethodTypeObjectWrite
  315.         
  316.     Methods from Shared
  317.         kQ3MethodTypeSharedEdited
  318.  
  319.     Renderer Methods
  320.     
  321.     The renderer methods should be implemented according to the type
  322.     of renderer being written.
  323.  
  324.     For the purposes of documentation, there are two basic types of
  325.     renderers: 
  326.  
  327.         Interactive
  328.             Interactive Renderer (QuickDraw 3Dâ„¢ RAVE)
  329.             WireFrame Renderer
  330.         
  331.         Deferred
  332.             a ray-tracer
  333.             painter's algorithm renderer (cached in a BSP triangle tree)
  334.             an artistic renderer (simulates a pencil drawing, etc.)
  335.  
  336.     The main difference is how each renderer handles incoming state and 
  337.     geometry.
  338.  
  339.     An interactive renderer immediately transforms, culls, and shades
  340.     incoming geometry and performs rasterization. For example, in a 
  341.     single-buffered WireFrame renderer, you will see a new triangle
  342.     immediately after Q3Triangle_Draw (if it's visible, of course).
  343.  
  344.     A deferred renderer caches the view state and each geometry, 
  345.     converting into any internal queue of drawing commands. Rasterization
  346.     is not actually performed until all data has been submitted.
  347.     
  348.     For example, a ray-tracer may not rasterize anything until the
  349.     end of the rendering loop, or until an EndFrame call is made.
  350. */
  351.  
  352. /******************************************************************************
  353.  **                                                                             **
  354.  **                            Renderer Support Flags                             **
  355.  **                                                                             **
  356.  *****************************************************************************/
  357. /*
  358.     kQ3MethodTypeRendererClassSupportFlag
  359.     TQ3RendererClassSupportFlagMethod
  360.     
  361.     Return the TQ3RendererClassSupportFlags for your renderer class. 
  362.  
  363.     kQ3RendererClassSupportFlagDoubleBuffer    
  364.         - the drawContext will not allocate or manage a back image buffer
  365.         - you must update the front buffer
  366.     kQ3RendererClassSupportFlagClearBuffer
  367.         - the drawContext will not be cleared before startFrame
  368.         - you must clear the image buffer with the desired drawcontext
  369.             method.
  370.  
  371.     If no method is supplied, the default is 0L.
  372.     
  373.     OPTIONAL
  374. */
  375. #define kQ3MethodTypeRendererClassSupportFlag \
  376.     Q3_METHOD_TYPE('r','d','s','f')
  377. typedef TQ3RendererClassSupportFlags TQ3RendererClassSupportFlagMethod;
  378.  
  379. /*
  380.     kQ3MethodTypeRendererGetEditFeatures
  381.     TQ3RendererGetEditFeaturesMethod
  382.     
  383.     Return the TQ3RendererFeatureFlags of the editable features of your 
  384.     renderer. 
  385.  
  386.     If no method is supplied, or the kQ3MethodTypeRendererSetFeatures is
  387.     NULL, the default editableFlags is kQ3RendererFeatureNone.
  388.     
  389.     OPTIONAL
  390. */
  391. #define kQ3MethodTypeRendererGetEditFeatures \
  392.     Q3_METHOD_TYPE('r','d','f','e')
  393. typedef TQ3Status (*TQ3RendererGetEditFeaturesMethod)(
  394.     TQ3RendererObject            renderer,
  395.     void                        *rendererPrivate,
  396.     TQ3RendererFeatureFlags        *editableFlags);
  397.  
  398. /*
  399.     kQ3MethodTypeRendererGetFeatures
  400.     TQ3RendererGetFeaturesMethod
  401.     
  402.     Return the TQ3RendererFeatureFlags of the current features set in
  403.     your renderer. 
  404.  
  405.     If no method is supplied, the default flags is kQ3RendererFeatureNone.
  406.     
  407.     OPTIONAL
  408. */
  409. #define kQ3MethodTypeRendererGetFeatures \
  410.     Q3_METHOD_TYPE('r','d','f','g')
  411. typedef TQ3Status (*TQ3RendererGetFeaturesMethod)(
  412.     TQ3RendererObject            renderer,
  413.     void                        *rendererPrivate,
  414.     TQ3RendererFeatureFlags        *flags);
  415.  
  416. /*
  417.     kQ3MethodTypeRendererSetFeatures
  418.     TQ3RendererSetFeaturesMethod
  419.     
  420.     Set the TQ3RendererFeatureFlags in the current features set of
  421.     your renderer. 
  422.  
  423.     Operation is:
  424.         newRendererFlags = 
  425.             (oldRendererFlags & ~editableFlags) |
  426.             (flags & editableFlags); 
  427.  
  428.     If no method is supplied, the Q3Renderer_GetEditFeatures always returns
  429.     kQ3RendererFeatureNone.
  430.     
  431.     OPTIONAL
  432. */
  433. #define kQ3MethodTypeRendererSetFeatures \
  434.     Q3_METHOD_TYPE('r','d','f','g')
  435. typedef TQ3Status (*TQ3RendererSetFeaturesMethod)(
  436.     TQ3RendererObject            renderer,
  437.     void                        *rendererPrivate,
  438.     TQ3RendererFeatureFlags        flags);
  439.     
  440. /******************************************************************************
  441.  **                                                                             **
  442.  **                        Renderer User Interface Methods                         **
  443.  **                                                                             **
  444.  *****************************************************************************/
  445.  
  446. /*===========================================================================*\
  447.     TQ3RendererModalConfigureMethod
  448.     
  449.     This method should pop up a modal dialog to edit the renderer settings 
  450.     found in the renderer private. 
  451.     
  452.     OPTIONAL
  453. \*===========================================================================*/
  454.  
  455. #define kQ3MethodTypeRendererModalConfigure \
  456.     Q3_METHOD_TYPE('r','d','m','c')
  457. typedef TQ3Status (*TQ3RendererModalConfigureMethod)(
  458.     TQ3RendererObject            renderer,
  459.     void                        *rendererPrivate);
  460.  
  461. /******************************************************************************
  462.  **                                                                             **
  463.  **                        Renderer Drawing State Methods                         **
  464.  **                                                                             **
  465.  *****************************************************************************/
  466. /*===========================================================================*\
  467.     TQ3RendererStartFrame
  468.     
  469.     The StartFrame method is called first at Q3View_StartRendering
  470.     and should:
  471.         - initialize any renderer state to defaults
  472.         - extract any and all useful data from the drawContext
  473.  
  474.     If your renderer passed in kQ3RendererFlagClearBuffer at 
  475.     registration, then it should also:
  476.         - clear the drawContext 
  477.     
  478.         When clearing, your renderer may opt to:
  479.         - NOT clear anything (if you touch every pixel, for example)
  480.         - to clear with your own routine, or
  481.         - to use the draw context default clear method by calling 
  482.         Q3DrawContext_Clear. Q3DrawContext_Clear takes advantage of
  483.         any available hardware in the system for clearing.
  484.     
  485.     This call also signals the start of all default submit commands from
  486.     the view. The renderer will receive updates for the default view
  487.     state via its Update methods before StartScene is called.
  488.     
  489.     REQUIRED
  490. \*===========================================================================*/
  491. #define kQ3MethodTypeRendererStartFrame    \
  492.     Q3_METHOD_TYPE('r','d','c','l')
  493. typedef TQ3Status (*TQ3RendererStartFrameMethod)(
  494.     TQ3ViewObject            view,
  495.     void                    *rendererPrivate,
  496.     TQ3DrawContextObject    drawContext);
  497.     
  498. /*===========================================================================*\
  499.     kQ3MethodTypeRendererStartScene
  500.     TQ3RendererStartSceneMethod
  501.     
  502.     The StartScene method is called during Q3View_StartRendering but after
  503.     the StartFrame command. It should:
  504.         - collect camera and light information
  505.     
  506.     If your renderer supports deferred camera transformation, camera is the
  507.     main camera which will be submitted in the hierarchy somewhere. It
  508.     is never NULL.
  509.  
  510.     If your renderer does not support deferred camera transformation, camera
  511.     is the transformed camera.
  512.  
  513.     If your renderer supports deferred light transformation, lights will be
  514.     NULL, and will be submitted to your light draw methods instead.
  515.  
  516.     This call signals the end of the default update state, and the start of submit
  517.     commands from the user to the view.
  518.  
  519.     REQUIRED
  520. \*===========================================================================*/
  521. #define kQ3MethodTypeRendererStartScene \
  522.     Q3_METHOD_TYPE('r','d','s','t')
  523. typedef TQ3Status (*TQ3RendererStartSceneMethod)(
  524.     TQ3ViewObject            view,
  525.     void                    *rendererPrivate,
  526.     TQ3CameraObject            camera,
  527.     TQ3GroupObject            lightGroup);
  528.  
  529. /*===========================================================================*\
  530.     kQ3MethodTypeRendererFlushFrame
  531.     TQ3RendererFlushFrameMethod
  532.     
  533.     This call is only implemented by asynchronous renderers.
  534.     
  535.     The FlushFrame method is called between the StartScene and EndScene
  536.     methods and is called when the user wishes to flush any asynchronous
  537.     drawing tasks (which draw to the drawcontext), but does not want 
  538.     to block.
  539.     
  540.     The result of this call is that an image should "eventually" appear
  541.     asynchronously.
  542.     
  543.     For asynchronous rendering, this call is non-blocking.
  544.     
  545.     An interactive renderer should ensure that all received
  546.     geometries are drawn in the image.
  547.     
  548.     An interactive renderer that talks to hardware should force
  549.     the hardware to generate an image.
  550.     
  551.     A deferred renderer should exhibit a similar behaviour,
  552.     though it is not required.  A deferred renderer should spawn
  553.     a process that generates a partial image from the currently
  554.     accumulated drawing state. 
  555.     
  556.     However, for renderers such as ray-tracers which generally are
  557.     quite compute-intensive, FlushFrame is not required and is a no-op.
  558.  
  559.     OPTIONAL
  560. \*===========================================================================*/
  561. #define kQ3MethodTypeRendererFlushFrame    \
  562.     Q3_METHOD_TYPE('r','d','f','l')
  563. typedef TQ3Status (*TQ3RendererFlushFrameMethod)(
  564.     TQ3ViewObject            view,
  565.     void                    *rendererPrivate,
  566.     TQ3DrawContextObject    drawContext);
  567.  
  568. /*===========================================================================*\
  569.     kQ3MethodTypeRendererEndScene
  570.     TQ3RendererEndSceneMethod
  571.     
  572.     The EndScene method is called at Q3View_EndRendering and signals
  573.     the end of submit commands to the view.
  574.  
  575.     If an error occurs, the renderer should call Q3Error_Post and
  576.     return kQ3ViewStatusError.
  577.     
  578.     If a renderer requires another pass on the renderering data,
  579.     it should return kQ3ViewStatusRetraverse.
  580.     
  581.     If rendering was cancelled, this function will not be called
  582.     and the view will handle returning kQ3ViewStatusCancelled;
  583.     
  584.     Otherwise, your renderer should begin completing the process of 
  585.     generating the image in the drawcontext. If you have buffered
  586.     any drawing data, flush it. RendererEnd should have a similar
  587.     effect as RendererFlushFrame.
  588.     
  589.     If the renderer is synchronous:
  590.         - complete rendering of the entire frame
  591.         if the renderer supports kQ3RendererClassSupportDoubleBuffer
  592.             - Update the front buffer
  593.         else
  594.             - DrawContext will update the front buffer after returning
  595.  
  596.     If the renderer is asynchronous
  597.         - spawn rendering thread for entire frame
  598.         if the renderer supports kQ3RendererClassSupportDoubleBuffer,
  599.             - you must eventually update the front buffer asynchronously
  600.         else
  601.             - you must eventually update the back buffer asynchronously
  602.             
  603.     REQUIRED
  604. \*===========================================================================*/
  605. #define kQ3MethodTypeRendererEndScene    \
  606.     Q3_METHOD_TYPE('r','d','e','d')
  607. typedef TQ3ViewStatus (*TQ3RendererEndSceneMethod)(
  608.     TQ3ViewObject            view,
  609.     void                    *rendererPrivate);
  610.  
  611. /*===========================================================================*\
  612.     kQ3MethodTypeRendererEndFrame
  613.     TQ3RendererEndFrame
  614.     
  615.     This call is only implemented by asynchronous renderers.
  616.  
  617.     The EndFrame method is called from Q3View_Sync, which is
  618.     called after Q3View_EndRendering and signals that the user
  619.     wishes to see the completed image and is willing to block.
  620.     
  621.     If your renderer supports kQ3RendererFlagDoubleBuffer
  622.         - update the front buffer completely 
  623.     else
  624.         - update the back buffer completely
  625.  
  626.     This call is equivalent in functionality to RendererFlushFrame
  627.     but blocks until the image is completed.
  628.     
  629.     If no method is supplied, the default is a no-op.
  630.     
  631.     NOTE: Registering a method of this type indicates that your renderer will
  632.     be rendering after Q3View_EndRendering has been called.
  633.     
  634.     OPTIONAL
  635. \*===========================================================================*/
  636. #define kQ3MethodTypeRendererEndFrame    \
  637.     Q3_METHOD_TYPE('r','d','s','y')
  638. typedef TQ3Status (*TQ3RendererEndFrameMethod)(
  639.     TQ3ViewObject            view,
  640.     void                    *rendererPrivate,
  641.     TQ3DrawContextObject    drawContext);
  642.     
  643. /*===========================================================================*\
  644.     The RendererCancel method is called after Q3View_StartRendering
  645.     and signals the termination of all rendering operations.
  646.  
  647.     A renderer should clean up any cached data, and cancel all 
  648.     rendering operations.
  649.     
  650.     If called before Q3View_EndRendering, the RendererEnd method
  651.     is NOT called.
  652.     
  653.     If called after Q3View_EndRendering, the renderer should kill
  654.     any threads and terminate any further rendering.
  655.     
  656.     REQUIRED
  657. \*===========================================================================*/
  658. #define kQ3MethodTypeRendererCancel    \
  659.     Q3_METHOD_TYPE('r','d','a','b')
  660. typedef void (*TQ3RendererCancelMethod)(
  661.     TQ3ViewObject            view,
  662.     void                    *rendererPrivate);
  663.  
  664. /******************************************************************************
  665.  **                                                                             **
  666.  **                        Renderer DrawContext Methods                         **
  667.  **                                                                             **
  668.  *****************************************************************************/
  669.  
  670. /*===========================================================================*\
  671.     kQ3MethodTypeRendererPush
  672.     TQ3RendererPushMethod
  673.     
  674.     kQ3MethodTypeRendererPop
  675.     TQ3RendererPopMethod
  676.     
  677.     These methods are called whenever the graphics state in the view
  678.     is pushed or popped. The user may isolate state by calling:
  679.     
  680.     Q3Attribute_Submit(kQ3AttributeTypeDiffuseColor, &red, view);
  681.     Q3Attribute_Submit(kQ3AttributeTypeTransparencyColor, &blue, view);
  682.     Q3Attribute_Submit(kQ3AttributeTypeSpecularColor, &white, view);
  683.     Q3Box_Submit(&unitBox, view);
  684.     Q3TranslateTransform_Submit(&unitVector, view);
  685.     Q3Push_Submit(view);
  686.         Q3Attribute_Submit(kQ3AttributeTypeDiffuseColor, &blue, view);
  687.         Q3Attribute_Submit(kQ3AttributeTypeTransparencyColor, &green, view);
  688.         Q3Box_Submit(&unitBox, view);
  689.     Q3Pop_Submit(view);    
  690.     Q3TranslateTransform_Submit(&unitVector, view);
  691.     Q3Box_Submit(&unitBox, view);
  692.     
  693.     or by submitting a display group which pushes and pops.
  694.     
  695.     If you support RendererPush and RendererPop in your renderer:
  696.         - you must maintain your drawing state as a stack, as well.
  697.         - you will not be updated with the popped state after
  698.             RendererPop is called.
  699.  
  700.     If you do not support Push and Pop in your renderer:
  701.         - you may maintain a single copy of the drawing state.
  702.         - you will be updated with changed fields after the view stack is
  703.             popped.
  704.  
  705.     A renderer that supports Push and Pop gets called in the following
  706.     sequence (from example above):
  707.     
  708.     RendererUpdateAttributeDiffuseColor(&red,...)
  709.     RendererUpdateAttributeTransparencyColor(&blue,...)
  710.     RendererUpdateAttributeSpecularColor(&white,...)
  711.     RendererUpdateMatrixLocalToWorld(...)
  712.     RendererSubmitGeometryBox(...)
  713.     RendererPush(...)
  714.         RendererUpdateAttributeDiffuseColor(&blue,...)
  715.         RendererUpdateAttributeTransparencyColor(&green,...)
  716.         RendererSubmitGeometryBox(...)
  717.     RendererPop(...)
  718.     RendererUpdateMatrixLocalToWorld(...)
  719.     RendererSubmitGeometryBox(...)
  720.  
  721.     A renderer that does not supports Push and Pop gets called in the
  722.     following sequence:
  723.     
  724.     RendererUpdateAttributeDiffuseColor(&red,...)
  725.     RendererUpdateAttributeTransparencyColor(&blue,...)
  726.     RendererUpdateAttributeSpecularColor(&white,...)
  727.     RendererUpdateMatrixLocalToWorld(...)
  728.     RendererSubmitGeometryBox(...)
  729.         RendererUpdateAttributeDiffuseColor(&blue,...)
  730.         RendererUpdateAttributeTransparencyColor(&green,...)
  731.         RendererSubmitGeometryBox(...)
  732.     RendererUpdateAttributeDiffuseColor(&red,...)
  733.     RendererUpdateAttributeTransparencyColor(&blue,...)
  734.     RendererUpdateMatrixLocalToWorld(...)
  735.     RendererSubmitGeometryBox(...)
  736.     
  737. \*===========================================================================*/
  738. #define kQ3MethodTypeRendererPush    \
  739.     Q3_METHOD_TYPE('r','d','p','s')
  740. typedef TQ3Status (*TQ3RendererPushMethod)(
  741.     TQ3ViewObject            view,
  742.     void                    *rendererPrivate);
  743.  
  744. #define kQ3MethodTypeRendererPop    \
  745.     Q3_METHOD_TYPE('r','d','p','o')
  746. typedef TQ3Status (*TQ3RendererPopMethod)(
  747.     TQ3ViewObject            view,
  748.     void                    *rendererPrivate);
  749.  
  750. /******************************************************************************
  751.  **                                                                             **
  752.  **                            Renderer Cull Methods                             **
  753.  **                                                                             **
  754.  *****************************************************************************/
  755. /*===========================================================================*\
  756.     kQ3MethodTypeRendererIsBoundingBoxVisible
  757.     TQ3RendererIsBoundingBoxVisibleMethod
  758.     
  759.     This method is called to cull complex groups and geometries 
  760.     given their bounding box in local space.
  761.     
  762.     It should transform the local-space bounding box coordinates to
  763.     frustum space and return a TQ3Boolean return value indicating
  764.     whether the box appears within the viewing frustum.
  765.     
  766.     If no method is supplied, the default behvaiour is to return
  767.     kQ3True.
  768.     
  769.     TODO: Default to cull to { (-1,1), (-1,1), (0,1) } frustum?
  770. \*===========================================================================*/
  771. #define kQ3MethodTypeRendererIsBoundingBoxVisible    \
  772.     Q3_METHOD_TYPE('r','d','b','x')
  773. typedef TQ3Boolean (*TQ3RendererIsBoundingBoxVisibleMethod)(
  774.     TQ3ViewObject            view,
  775.     void                    *rendererPrivate,
  776.     const TQ3BoundingBox    *bBox);
  777.  
  778. #if defined(ESCHER_VER_15) && ESCHER_VER_15
  779.  
  780. /******************************************************************************
  781.  **                                                                             **
  782.  **                            Renderer Cache Methods                             **
  783.  **                                                                             **
  784.  *****************************************************************************/
  785.  
  786. /*===========================================================================*\
  787.     kQ3MethodTypeRendererStartCache
  788.     TQ3RendererStartCacheMethod
  789.     
  790.     The start cache method is called at Q3View_StartRendererCache and
  791.     signals that the application wishes to bracket some information
  792.     that is static within a scene.
  793.     
  794.     If rendererCache is NULL, then the renderer should prepare to cache
  795.     all information until the EndCache method is called.
  796.     
  797.     If rendererCache is non-NULL, then the renderer should validate the
  798.     pre-existing cache.
  799.     
  800.     If the cache is invalid, the call should return kQ3True (meaning
  801.     please retraverse the data) and delete the cache. The renderer
  802.     should prepare to cache all submitted information until the EndCache
  803.     method is called.
  804.     
  805.     If the cache is valid, the renderer should apply the cache to its
  806.     state and/or the image, and return kQ3False (don't retraverse the
  807.     data). EndCache will not be called.
  808.     
  809.     If no method is supplied, the default is to return kQ3True.
  810.     
  811.     OPTIONAL
  812. \*===========================================================================*/
  813. #define kQ3MethodTypeRendererStartCache    \
  814.     Q3_METHOD_TYPE('r','d','b','c')
  815. typedef TQ3Boolean (*TQ3RendererStartCacheMethod)(
  816.     TQ3ViewObject            view,
  817.     void                    *rendererPrivate,
  818.     void                    *rendererCache);
  819.  
  820. /*===========================================================================*\
  821.     kQ3MethodTypeRendererEndCache
  822.     TQ3RendererEndCacheMethod
  823.     
  824.     The end cache method is called at Q3View_EndRenderingCache and
  825.     indicates that all cached information has been submitted. It
  826.     returns a pointer to a private data structure containing the
  827.     cached data. EndCache will only be called after StartCache.
  828.  
  829.     If NULL is returned, it indicates that the renderer can not
  830.     cache the information.
  831.     
  832.     If no method is supplied, the default is to return NULL.
  833.     
  834.     OPTIONAL
  835. \*===========================================================================*/
  836. #define kQ3MethodTypeRendererEndCache    \
  837.     Q3_METHOD_TYPE('r','d','e','c')
  838. typedef void *(*TQ3RendererEndCacheMethod)(
  839.     TQ3ViewObject            view,
  840.     void                    *rendererPrivate);
  841.  
  842. /*===========================================================================*\
  843.     kQ3MethodTypeRendererDeleteCache
  844.     TQ3RendererDeleteCacheMethod
  845.     
  846.     The delete cache method is called on a cache that has been 
  847.     invalidated.
  848.     
  849.     NOTE: When the RendererStartCache method is passed a cache to 
  850.     validate and it returns kQ3True (cache is invalid, please
  851.     retraverse data), this method is NOT called on the invalid cache.
  852.     It is up to the renderer to delete or re-use the cache passed in.
  853.     
  854.     If no method is supplied, caches are assumed to be unsupported, or
  855.     freed by the renderer.
  856.     
  857.     OPTIONAL
  858. \*===========================================================================*/
  859. #define kQ3MethodTypeRendererDeleteCache \
  860.     Q3_METHOD_TYPE('r','d','d','c')
  861. typedef TQ3Status (*TQ3RendererDeleteCacheMethod)(
  862.     TQ3RendererObject        renderer,
  863.     void                    *rendererPrivate,
  864.     void                    *rendererCache);
  865.  
  866. #endif /* ESCHER_VER_15 */
  867.  
  868. /******************************************************************************
  869.  **                                                                             **
  870.  **                        Renderer Object Support Methods                         **
  871.  **                                                                             **
  872.  *****************************************************************************/
  873.  
  874. /*===========================================================================*\
  875.  *
  876.  *    Drawing methods (Geometry, Camera, Lights)
  877.  *
  878. \*===========================================================================*/
  879.  
  880. /*
  881.     Geometry MetaHandler
  882.     
  883.     This metaHandler is required to support 
  884.     
  885.     kQ3GeometryTypeTriangle
  886.     kQ3GeometryTypeLine
  887.     kQ3GeometryTypePoint
  888.     kQ3GeometryTypePixmapMarker
  889.     
  890.     REQUIRED
  891. */
  892. #define kQ3MethodTypeRendererSubmitGeometryMetaHandler    \
  893.     Q3_METHOD_TYPE('r','d','g','m')
  894. typedef TQ3FunctionPointer (*TQ3RendererSubmitGeometryMetaHandlerMethod)(
  895.     TQ3ObjectType                    geometryType);
  896. /*
  897.     The TQ3RendererSubmitGeometryMetaHandlerMethod switches on geometryType
  898.     of kQ3GeometryTypeFoo and returns methods of type:
  899. */
  900. typedef TQ3Status (*TQ3RendererSubmitGeometryMethod)(
  901.     TQ3ViewObject                    view,
  902.     void                            *rendererPrivate,
  903.     TQ3GeometryObject                geometry,
  904.     const void                        *publicData);
  905.  
  906.  
  907. /*
  908.     Camera MetaHandler
  909.     
  910.     This metaHandler, if supplied, indicates that your renderer
  911.     handles deferred transformation of the main camera within a scene.
  912.     
  913.     If not supplied, or an unsupported camera is used, the view will do
  914.     the transformation for the renderer and pass in a camera in the 
  915.     StartScene method.
  916.     
  917.     OPTIONAL
  918. */
  919. #define kQ3MethodTypeRendererSubmitCameraMetaHandler    \
  920.     Q3_METHOD_TYPE('r','d','c','m')
  921. typedef TQ3FunctionPointer (*TQ3RendererSubmitCameraMetaHandlerMethod)(
  922.     TQ3ObjectType                    cameraType);
  923. /*
  924.     The TQ3RendererSubmitCameraMetaHandlerMethod switches on cameraType
  925.     of kQ3CameraTypeFoo and returns methods of type:
  926. */
  927. typedef TQ3Status (*TQ3RendererSubmitCameraMethod)(
  928.     TQ3ViewObject                    view,
  929.     void                            *rendererPrivate,
  930.     TQ3CameraObject                    camera,
  931.     const void                        *publicData);
  932.  
  933.  
  934. /*
  935.     Light MetaHandler
  936.     
  937.     This metaHandler, if supplied, indicates that your renderer
  938.     handles deferred transformation of lights within a scene.
  939.     
  940.     If an unsupported light is encountered, it is ignored.
  941.  
  942.     OPTIONAL
  943. */
  944. #define kQ3MethodTypeRendererSubmitLightMetaHandler    \
  945.     Q3_METHOD_TYPE('r','d','l','g')
  946. typedef TQ3FunctionPointer (*TQ3RendererSubmitLightMetaHandlerMethod)(
  947.     TQ3ObjectType                    lightType);
  948. /*
  949.     The TQ3RendererSubmitLightMetaHandlerMethod switches on lightType
  950.     of kQ3LightTypeFoo and returns methods of type:
  951. */
  952. typedef TQ3Status (*TQ3RendererSubmitLightMethod)(
  953.     TQ3ViewObject                    view,
  954.     void                            *rendererPrivate,
  955.     TQ3LightObject                    light,
  956.     const void                        *publicData);
  957.  
  958. /*===========================================================================*\
  959.  *
  960.  *    Update methods
  961.  *
  962.  *    They are called whenever the state has changed. If the renderer supports
  963.  *    the RendererPush and RendererPop methods, it must maintain its own state
  964.  *    stack. Updates are not called for changed data when the view stack is
  965.  *    popped.
  966.  *
  967.  *    See the comments for the RendererPush and RendererPop methods above
  968.  *    for an example of how data is updated.
  969.  *
  970. \*===========================================================================*/
  971.  
  972. /*
  973.     Style
  974. */
  975. #define kQ3MethodTypeRendererUpdateStyleMetaHandler        \
  976.     Q3_METHOD_TYPE('r','d','y','u')
  977. typedef TQ3FunctionPointer (*TQ3RendererUpdateStyleMetaHandlerMethod)(
  978.     TQ3ObjectType                    styleType);
  979. /*
  980.     The TQ3RendererUpdateStyleMetaHandlerMethod switches on styleType
  981.     of kQ3StyleTypeFoo and returns methods of type:
  982. */
  983. typedef TQ3Status (*TQ3RendererUpdateStyleMethod)(
  984.     TQ3ViewObject                    view,
  985.     void                            *rendererPrivate,
  986.     const void                        *publicData);
  987.  
  988. /*
  989.     Attributes
  990. */
  991. #define kQ3MethodTypeRendererUpdateAttributeMetaHandler    \
  992.     Q3_METHOD_TYPE('r','d','a','u')
  993. typedef TQ3FunctionPointer (*TQ3RendererUpdateAttributeMetaHandlerMethod)(
  994.     TQ3AttributeType                attributeType);
  995. /*
  996.     The TQ3RendererUpdateStyleMetaHandlerMethod switches on attributeType
  997.     of kQ3AttributeTypeFoo and returns methods of type:
  998. */
  999. typedef TQ3Status (*TQ3RendererUpdateAttributeMethod)(
  1000.     TQ3ViewObject                    view,
  1001.     void                            *rendererPrivate,
  1002.     const void                        *publicData);
  1003.  
  1004. /*
  1005.     Shaders
  1006. */
  1007. #define kQ3MethodTypeRendererUpdateShaderMetaHandler    \
  1008.     Q3_METHOD_TYPE('r','d','s','u')
  1009. typedef TQ3FunctionPointer (*TQ3RendererUpdateShaderMetaHandlerMethod)(
  1010.     TQ3ObjectType                    shaderType);
  1011. /*
  1012.     The TQ3RendererUpdateShaderMetaHandlerMethod switches on shaderType
  1013.     of kQ3ShaderTypeFoo and returns methods of type:
  1014. */
  1015. typedef TQ3Status (*TQ3RendererUpdateShaderMethod)(
  1016.     TQ3ViewObject                    view,
  1017.     void                            *rendererPrivate,
  1018.     TQ3Object                        shaderObject);
  1019.  
  1020. /*
  1021.     Matricies
  1022. */
  1023. #define kQ3MethodTypeRendererUpdateMatrixMetaHandler    \
  1024.     Q3_METHOD_TYPE('r','d','x','u')
  1025. typedef TQ3MetaHandler TQ3RendererUpdateMatrixMetaHandlerMethod;
  1026. /*
  1027.     The TQ3RendererUpdateShaderMetaHandlerMethod switches on methods
  1028.     of the form kQ3MethodTypeRendererUpdateMatrixFoo:
  1029. */
  1030. #define kQ3MethodTypeRendererUpdateMatrixLocalToWorld    \
  1031.     Q3_METHOD_TYPE('u','l','w','x')
  1032. #define kQ3MethodTypeRendererUpdateMatrixLocalToWorldInverse    \
  1033.     Q3_METHOD_TYPE('u','l','w','i')
  1034. #define kQ3MethodTypeRendererUpdateMatrixLocalToWorldInverseTranspose    \
  1035.     Q3_METHOD_TYPE('u','l','w','t')
  1036. #define kQ3MethodTypeRendererUpdateMatrixLocalToCamera    \
  1037.     Q3_METHOD_TYPE('u','l','c','x')
  1038. #define kQ3MethodTypeRendererUpdateMatrixLocalToFrustum    \
  1039.     Q3_METHOD_TYPE('u','l','f','x')
  1040.  
  1041. /*
  1042.     and returns methods of type:
  1043. */
  1044. typedef TQ3Status (*TQ3RendererUpdateMatrixMethod)(
  1045.     TQ3ViewObject                    view,
  1046.     void                            *rendererPrivate,
  1047.     const TQ3Matrix4x4                *matrix);
  1048.  
  1049. #ifdef __cplusplus
  1050. }
  1051. #endif    /* __cplusplus */
  1052.  
  1053. #if defined(__MWERKS__)
  1054.     #pragma enumsalwaysint reset
  1055. #elif defined(__xlc) || defined(__xlC) || defined(__xlC__) || defined(__XLC121__)
  1056.     #pragma options enum=reset
  1057. #endif
  1058.  
  1059. #endif  /*  QD3DRenderer_h  */
  1060.